import cv2

img = cv2.imread("../images/cat.jpg")

# 1. 灰度化
img_gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

# 2. 二值化
_, img_binary = cv2.threshold(img_gray,127,255,
                              cv2.THRESH_BINARY+cv2.THRESH_OTSU)

# 3. 高斯滤波
img_gaussian = cv2.GaussianBlur(img_binary,(5,5),sigmaX=3)

# 4. 边缘检测
# 包含 Sobel计算梯度和方向、非极大值抑制、双阈值筛选
img_canny =cv2.Canny(
    img_gaussian,
    30,
    70
)

cv2.imshow('img_canny', img_canny)
cv2.waitKey(0)